package com.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;

public class UserAction2 {
	private String username;
	private File[]  upload;
	private String[] uploadContentType;
	private String[] uploadFileName;
	
	
	public String execute() throws Exception{
		//1.获取上传的文件绝对路径
		String path = ServletActionContext.getServletContext().getRealPath("/upload");
		//2.创建输出流，位置是服务器
		for(int i=0; i<upload.length; i++){
			FileOutputStream fos = new FileOutputStream(path+"\\"+uploadFileName[i]);
			//3.创建输入流对象，上传的文件---在临时路径
			FileInputStream fis = new FileInputStream(upload[i]);
			IOUtils.copy(fis, fos);
		}
		return "success";
	}


	public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public File[] getUpload() {
		return upload;
	}


	public void setUpload(File[] upload) {
		this.upload = upload;
	}


	public String[] getUploadContentType() {
		return uploadContentType;
	}


	public void setUploadContentType(String[] uploadContentType) {
		this.uploadContentType = uploadContentType;
	}


	public String[] getUploadFileName() {
		return uploadFileName;
	}


	public void setUploadFileName(String[] uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	
}
